package com.globallogic.javatraining.liudmyla_shapoval.uni.organization;

import java.util.ArrayList;
import java.util.List;

import com.globallogic.javatraining.liudmyla_shapoval.uni.people.Student;
import com.globallogic.javatraining.liudmyla_shapoval.uni.resources.Course;

/**
 * 
 * Enrollment class, used to enroll student to a course making instance of EnrollmentUnit. 
 * 
 */

public class Enrollment {

	private ArrayList<EnrollmentUnit> enrollments = new ArrayList<EnrollmentUnit>();

	public void enroll(Student student, Course course) {
		if (!isEnrolled(student, course)) {
			enrollments.add(new EnrollmentUnit(student, course));
		}
	}

	public boolean isEnrolled(Student student, Course course) {
		for (EnrollmentUnit e : enrollments) {
			if (e.course.equals(course) && e.student.equals(student)) {
				return true;
			}
		}
		return false;
	}

	public List<Course> getTakenCourses(Student student) {
		List<Course> takenCourses = new ArrayList<Course>();
		for (EnrollmentUnit e : enrollments) {
			if (e.student.equals(student)) {
				takenCourses.add(e.course);
			}
		}
		return takenCourses;
	}

}
